package cn.group.hotel2.controller;

import cn.group.hotel2.pojo.dto.TypeAddNewDTO;
import cn.group.hotel2.pojo.dto.TypeUpdateDTO;
import cn.group.hotel2.pojo.vo.TypeListItemVO;
import cn.group.hotel2.pojo.vo.TypeStandardVO;
import cn.group.hotel2.service.ITypeService;
import cn.group.hotel2.web.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/type")
public class TypeController {

    @Autowired
    private ITypeService typeService;

    @GetMapping("/list/{currentPage}")
    public JsonResult<List<TypeListItemVO>> list(@PathVariable Integer currentPage){
        Integer current = (currentPage-1)*10;
        return JsonResult.ok(typeService.list(current));
    }

    @GetMapping("/getAll")
    public JsonResult<List<TypeListItemVO>> getAll(){
        return JsonResult.ok(typeService.getAll());
    }

    @GetMapping("/count")
    public JsonResult<Integer> count(){
        return JsonResult.ok(typeService.getCount());
    }

    @PostMapping("/add-new")
    public JsonResult<Void> addNew(TypeAddNewDTO typeAddNewDTO){
        typeService.addNew(typeAddNewDTO);
        return JsonResult.ok();
    }

    @PostMapping("/{id}/update")
    public JsonResult<Void> updateById(@PathVariable Long id, TypeUpdateDTO typeUpdateDTO){
        typeService.updateById(id,typeUpdateDTO);
        return JsonResult.ok();
    }

    @GetMapping("/{id}")
    public JsonResult<TypeStandardVO> getUpdateStandardById(@PathVariable Long id){
        return JsonResult.ok(typeService.getUpdateStandardById(id));
    }

    @PostMapping("/{id}/delete")
    public JsonResult<Void> deleteById(@PathVariable Long id){
        typeService.deleteById(id);
        return JsonResult.ok();
    }



}
